package com.aaa.service.impl;

import com.aaa.dao.QuestionFPADao;
import com.aaa.entity.PageSort;
import com.aaa.entity.Question;
import com.aaa.service.QuestionFPAService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：Lim
 * @date ：Created in 2022/6/28 9:03
 * @description：业务层实现类
 * @modified By：
 * @version: 1.0
 */
@Service
public class QuestionFPAServiceImpl implements QuestionFPAService {
    @Autowired
    private QuestionFPADao questionDao;
    @Override
    public com.github.pagehelper.Page selectQuestion(PageSort pageSort, Question question) {
        if (pageSort.getField()!=null && pageSort.getField()!="") {
            Page<Question> page = PageHelper.startPage(pageSort.getPage(), pageSort.getLimit(), pageSort.getField() + " " + pageSort.getOrder());
        }else{
            Page<Question> page = PageHelper.startPage(pageSort.getPage(), pageSort.getLimit());
        }
        List<Question> questionList = questionDao.selectQuestion(question);
        com.github.pagehelper.Page listPage= ( com.github.pagehelper.Page) questionList;
        return listPage;
    }

    @Override
    public boolean insertQuestion(Question question) {
        int i = questionDao.insertQuestion(question);
        if(i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteQuestion(Integer id) {
        int i= questionDao.deleteQuestionByid(id);
        if(i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateQuestion(Question question) {
        int i = questionDao.updateQuestionInt(question);
        if (i > 0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteQuestionByAllId(String[] id) {
        int i = questionDao.deleteQuestionByAllid(id);
        if (i > 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<Question> answer(Question question) {
        return questionDao.answer(question);
    }


}